import sys
import os
from PySide6.QtWidgets import *
from PySide6.QtGui import *
from PySide6.QtCore import *

class Demo(QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.parent = parent
        layout = QVBoxLayout()
        layout.setAlignment(Qt.AlignmentFlag.AlignTop)

        group=QGroupBox('Default Label')
        groupLayout=QVBoxLayout()
        label=QLabel()
        label.setText('Default Label')
        groupLayout.addWidget(label)

        label=QLabel()
        label.setNum(1.01)
        groupLayout.addWidget(label)

        label=QLabel()
        label.setNum(5)
        groupLayout.addWidget(label)

        label=QLabel('Blue Background Label')
        label.setAutoFillBackground(True)#必须，不然背景色不生效
        palette=QPalette()
        palette.setColor(QPalette.ColorRole.Window,Qt.blue)
        label.setPalette(palette)
        groupLayout.addWidget(label)

        label=QLabel('Red Foreground Label')
        palette=QPalette()
        palette.setColor(QPalette.ColorRole.WindowText,Qt.red)
        label.setPalette(palette)
        groupLayout.addWidget(label)  

        group.setLayout(groupLayout)
        layout.addWidget(group)

        groupHtml=QGroupBox('Html Label')
        layoutHtml=QVBoxLayout()
        labelHtml=QLabel("<a href='www.baidu.com'>这是一个html标签</a><font color='red'>hello <b>world</b></font>")
        layoutHtml.addWidget(labelHtml)
        groupHtml.setLayout(layoutHtml)
        layout.addWidget(groupHtml)

        hLayout=QHBoxLayout()

        groupPic=QGroupBox('Picture Label')
        layoutPic=QVBoxLayout()
        labelPic=QLabel()
        labelPic.setPixmap(QPixmap(f'{self.parent.getAppDir()}/resources/qtforpython.png'))
        layoutPic.addWidget(labelPic)
        groupPic.setLayout(layoutPic)
        hLayout.addWidget(groupPic)

        groupGif=QGroupBox('Gif Label')
        layoutGif=QVBoxLayout()
        labelGif=QLabel()        
        movie=QMovie(f'{self.parent.getAppDir()}/resources/loading.gif')
        movie.start()
        labelGif.setMovie(movie)
        layoutGif.addWidget(labelGif)
        groupGif.setLayout(layoutGif)
        hLayout.addWidget(groupGif)

        layout.addLayout(hLayout)
        self.setLayout(layout)

def runDemo(parent):
    wigdet =  Demo(parent)
    return wigdet